package sample.service.antisamy.impl;

import javax.annotation.Resource;

import org.owasp.validator.html.AntiSamy;
import org.owasp.validator.html.CleanResults;
import org.owasp.validator.html.Policy;
import org.springframework.stereotype.Service;
import org.w3c.dom.DocumentFragment;

import sample.intf.antisamy.service.IAntisamyService;

@Service
public class AntisamyService implements IAntisamyService {

	@Resource
	Policy antisamyPolicy;

	@Override
	public CleanResults sanitizeHtml(String html) throws Exception {
		AntiSamy as = new AntiSamy();
		CleanResults cr = as.scan(html, antisamyPolicy);
		return cr;
	}

	@Override
	public String sanitizeHtmlToString(String html) throws Exception {
		AntiSamy as = new AntiSamy();
		CleanResults cr = as.scan(html, antisamyPolicy);
		return cr.getCleanHTML();
	}

	@Override
	public DocumentFragment sanitizeHtmlToDom(String html) throws Exception {
		AntiSamy as = new AntiSamy();
		CleanResults cr = as.scan(html, antisamyPolicy);
		return cr.getCleanXMLDocumentFragment();
	}
}
